package cn.edu.tju.elm.service.Impl;

import cn.edu.tju.elm.model.Cart;
import cn.edu.tju.elm.repository.CartRepository;
import cn.edu.tju.elm.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class CartServiceImpl implements CartService {

    private final CartRepository cartRepository;

    @Autowired
    public CartServiceImpl(CartRepository cartRepository) {
        this.cartRepository = cartRepository;
    }

    @Override
    public Optional<Cart> findById(Long id) {
        return cartRepository.findById(id);
    }

    @Override
    public List<Cart> findByCustomerId(Long customerId) {
        return cartRepository.findByCustomerId(customerId);
    }

    @Override
    public Optional<Cart> findByCustomerIdAndFoodId(Long customerId, Long foodId) {
        return cartRepository.findByCustomerIdAndFoodId(customerId, foodId);
    }

    @Override
    public List<Cart> findByCustomerIdAndBusinessId(Long customerId, Long businessId){
        return cartRepository.findByCustomerIdAndBusinessId(customerId, businessId);
    }

    @Override
    public Cart save(Cart cart) {
        return cartRepository.save(cart);
    }

    @Override
    public void deleteById(Long id) {
        cartRepository.deleteById(id);
    }

    @Override
    public void deleteByCustomerIdAndFoodId(Long customerId, Long foodId) {
        cartRepository.deleteByCustomerIdAndFoodId(customerId, foodId);
    }
}